// blatently stolen from my GL project.

#ifndef SETUTILITY_H___
#define SETUTILITY_H___

#include <set>

/** The sole purpose of this utility class is to wrap up common set operations
 * so i don't mess up the arguments of std::set_difference and so on.
 */
struct SetUtility {
	/** return the set difference of the two set
	 * @param s1 the first set
	 * @param s2 the second set
	 * @return a set by value that contains all elements of s1 that are not on s2
	 */
	template <typename T>
	static std::set<T> difference(const std::set<T>& s1,
			const std::set<T>& s2) {
		std::set<T> result;
		std::set_difference(s1.begin(), s1.end(), s2.begin(), s2.end(),
				std::inserter(result, result.end()));
		return result;
	}
	/** return the set union of the two set
	 * @param s1 the first set
	 * @param s2 the second set
	 * @return a set by value that contains all elements of s1 and all elements of s2
	 */
	template <typename T>
	static std::set<T> _union(const std::set<T>& s1,
			const std::set<T>& s2) {
		std::set<T> result;
		std::set_union(s1.begin(), s1.end(), s2.begin(), s2.end(),
				std::inserter(result, result.end()));
		return result;
	}

	/** return the set intersection of the two set
	 * @param s1 the first set
	 * @param s2 the second set
	 * @return a set by value that contains elements that are in both set.
	 */
	template <typename T>
	static std::set<T> intersection(const std::set<T>& s1,
			const std::set<T>& s2) {
		std::set<T> result;
		std::set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(),
				std::inserter(result, result.end()));
		return result;
	}
};


#endif /* SETUTILITY_H___ */
